<?php
session_start();
require_once('config/config.php');
/* connessione al db */
$mysqli = new mysqli($_CFG[connect][host], $_CFG[connect][user], $_CFG[connect][pass], $_CFG[connect][database]);

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

        echo '
        <fieldset>
        <legend>Scontrini</legend>';
		if($_CFG[printer][riserved_session]) $sql_session = " AND sessione = '".session_id()."'";
        $query_p = "SELECT *, DATE_FORMAT(dataora, '%H:%i:%s') AS ora FROM `documenti` WHERE IDdocstato != ".$_CFG[stati][eliminato]." AND `dataora` > DATE_SUB(CURDATE(), INTERVAL ".$_CFG[printer][interval].")".$sql_session." ORDER BY `dataora` DESC";
        if($_CFG[debug]) echo $query_p;
		if ($result = $mysqli->query($query_p)) {

            /* fetch associative array */
            while ($row = $result->fetch_assoc()) {
                echo "\t".'<div class="righe" id="doc-'.$row["IDdocumento"].'">'
                .'n.: <strong>'.$row["numero"].'</strong>'
                .' / tavolo: <strong>'.$row["tavolo"].'</strong>'
                .' / nome: <strong>'.$row["nome"].'</strong>'
                #.' / dataora: '.$row["dataora"].'<br />'
				.' / ora: <strong>'.$row["ora"].'</strong>'
                .'<span class="right">'
                .'<button id="mod-'.$row["IDdocumento"].'" class="button black small">Dettaglio</button> '
                //.'<button id="stampa-'.$row["IDdocumento"].'" class="button green small">STAMPA</button>'
				//.'<script type=\'text/javascript\'>$(\'#stampa-'.$row["IDdocumento"].'\').click(function(){$(\'#prodotti\').load(\'stampa.php?id='.$row["IDdocumento"].'\')})</script>'
				.'<button id="stampa-'.$row["IDdocumento"].'" class="button small green" href="stampa.php?id='.$row["IDdocumento"].'">STAMPA</button>'
				."<script type='text/javascript'>
				$(\"#stampa-".$row["IDdocumento"]."\").fancybox({
						'width'				: '100%',
						'height'			: '100%',
						'autoScale'			: false,
						'transitionIn'		: 'none',
						'transitionOut'		: 'none',
						'type'				: 'iframe'
				});
				</script>"
                .'</span>'
                .'</div>'."\n"
                .'<div class="righeopen" id="docdet-'.$row["IDdocumento"].'"><center><img src="images/ajax-loader.gif" alt="preloader..." /></center></div>';
                echo "\n\t\t".'<script type="text/javascript">'
                .'$("#mod-'.$row["IDdocumento"].'").click(function () {
                    if ($("#docdet-'.$row["IDdocumento"].'").is(":hidden")) {
                        $("#docdet-'.$row["IDdocumento"].'").slideDown(200);
                        $("#docdet-'.$row["IDdocumento"].'").load(\'ajax.php?case=cartrighe&id='.$row["IDdocumento"].'\');
                    } else {
                        $("#docdet-'.$row["IDdocumento"].'").slideUp(200);
                    }
                });'
                .'</script>'."\n";
				//echo "\t\t".'<script type="text/javascript">$(\'#doc-'.$row["IDdocumento"].'\').click(function(){$(\'#cassa\').load(\'ajax.php?case=pro&id='.$row["IDprodotto"].'\')})</script>'."\n";

			}

			/* free result set */
			$result->free();
		}